#define _CRT_SECURE_NO_WARNINGS 1

#include"Stack.h"

void STInit(ST* st)
{
	assert(st);
	st->date = NULL;
	st->capacity = st->top = 0;
}
void STDestory(ST* st)
{
	assert(st);
	free(st->date);
	st->date = NULL;
	st->top = 0;
	st->capacity = 0;
}
void STPush(ST* st, STDateType x)
{
	assert(st);

	if (st->top == st->capacity)
	{
		size_t newcapacity = (st->capacity == 0 ? 4 : 2 * st->capacity);
		STDateType* tmp = (STDateType*)realloc(st->date, sizeof(STDateType) * newcapacity);
		if (tmp != NULL)
		{
			st->date = tmp;
			st->capacity = newcapacity;
		}
	}

	st->date[st->top++] = x;
}
void STPop(ST* st)
{
	assert(st);
	assert(st->top > 0);
	st->top--;
}
STDateType STTop(ST* st)
{
	assert(st);
	assert(st->top > 0);
	return st->date[st->top - 1];
}
bool STEmpty(ST* st)
{
	assert(st);
	return st->top == 0;
}
int STSize(ST* st)
{
	assert(st);
	return st->top;
}